/**
 * Created by eva on 2019/12/29.
 */
function Mom(){
    this.x;
    this.y;
    this.angle;

    this.bigTails = [];
    this.bigTailTimer = 0;
    this.bigTailIndex = 0;
    this.bigEyes = [];
    this.bigEyeTimer = 0;
    this.bigEyeIndex = 0;
    this.bigEyeInterval = 2000;

    this.babySwim = [];
    this.babyFadeTimer = 0;
    this.babyFadeIndex = 0;

    this.bigOrange = [];
    this.bigOrangeIndex = 0;

    this.bigBlue = [];
    this.bigBlueIndex = 0;
}
Mom.prototype = {
    init : function () {
        this.x = canWidth*0.5;
        this.y = canHeight*0.5;
        this.angle = 0;
        for(var i = 0; i < 8; i++){
            this.bigTails[i] = new Image();
            this.bigTails[i].src = "./src/bigTail"+i+".png";
        }

        for(var i = 0; i < 2; i++){
            this.bigEyes[i] = new Image();
            this.bigEyes[i].src = "./src/bigEye"+i+".png";
        }

        for(var i = 0; i < 8; i++){
            this.bigOrange[i] = new Image();
            this.bigOrange[i].src = "./src/bigSwim"+i+".png";
        }

        for(var i = 0; i < 8; i++){
            this.bigBlue[i] = new Image();
            this.bigBlue[i].src = "./src/bigSwimBlue"+i+".png";
        }
    },
    draw : function () {
        //lerp x,y
        this.x = lerpDistance(mx,this.x,0.98);
        this.y = lerpDistance(my,this.y,0.98);

        this.bigTailTimer += deltaTime;
        if(this.bigTailTimer > 50){
            this.bigTailIndex++;
            this.bigTailIndex = this.bigTailIndex%8;
            this.bigTailTimer = 0;

        }

        this.bigEyeTimer += deltaTime;
        if(this.bigEyeTimer  > this.bigEyeInterval){
            this.bigEyeIndex = (this.bigEyeIndex+1)%2;
            this.bigEyeTimer %= this.bigEyeInterval;
            if(this.bigEyeIndex == 0){
                this.bigEyeInterval = Math.random()*1500 + 2000;
            }else{
                this.bigEyeInterval = 200;
            }
        }


        //delta angle
        //math atan2(y,x);
        var deltaY = my - this.y;
        var deltaX = mx - this.x;
        var beta = Math.atan2(deltaY,deltaX)+Math.PI;

        //lerp angle
        this.angle  = lerpAngle(beta, this.angle, 0.6);


        ctx1.save();
        ctx1.translate(this.x,this.y);
        ctx1.rotate(this.angle);

        var eye = this.bigEyes[this.bigEyeIndex];
        var tail = this.bigTails[this.bigTailIndex];
        var body = data.double == 2 ? this.bigBlue[this.bigBlueIndex%8] : this.bigOrange[this.bigOrangeIndex%8];
        ctx1.drawImage(eye, -eye.width*0.5, -eye.height*0.5);
        ctx1.drawImage(body, -body.width*0.5,-body.height*0.5);
        ctx1.drawImage(tail, -tail.width*0.5+30, -tail.height*0.5);
        ctx1.restore();
    }
}
